﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using PropertyChanged;

namespace AllInOne.MainPages
{
    //弹出框传递数据
    public delegate void DlgDialog(string value);

    /// <summary>
    /// PlateInputWindow.xaml 的交互逻辑
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class PlateInputWindow : Window
    {
        public event DlgDialog DlgDialogEvent_InputPlate;

        public PlateInputWindow(string plate)
        {
            InitializeComponent();
            Plate = plate;
        }

        #region 界面绑定属性

        public string Plate { get; set; } = string.Empty;

        #endregion
        /// <summary>
        /// 点击车牌省份简称
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is TextBlock tb) Plate += tb.Text;
        }

        private void BackSpace(object sender, RoutedEventArgs e)
        {
            if (Plate.Length > 0)
                Plate = Plate.Remove(Plate.Length - 1, 1);
        }

        private void Clear(object sender, RoutedEventArgs e)
        {
            Plate = string.Empty;
        }

        private void Ok_OnClick(object sender, RoutedEventArgs e)
        {
            //DialogResult = true;
            Close();
            if (DlgDialogEvent_InputPlate != null)
            {
                DlgDialogEvent_InputPlate(Plate);
            }
        }

        private void Close(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void UIElement_OnMouseEnter(object sender, MouseEventArgs e)
        {
            if (sender is TextBlock tx) tx.Background = (Brush) FindResource("PrimaryBrush");
        }

        private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
        {
            if (sender is TextBlock tx) tx.Background = null;
        }
    }
}
